﻿package mortal.game.view.guide
{
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.gLinkText.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.task.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuideTaskFlyWin extends SmallWindow
    {
        private var _txt:GTextFiled;
        private var _btn:GButton;
        private var _info:TaskInfo;
        private var _timer:SecTimer;
        private var _leftTime:int = 0;
        private static var _instance:GuideTaskFlyWin;

        public function GuideTaskFlyWin(param1:ILayer = null)
        {
            super(param1);
            this.setSize(280, 170);
            this.title = Language.getString(21027);
            return;
        }// end function

        private function startTimer() : void
        {
            if (this._timer == null)
            {
                this._timer = new SecTimer(1);
                this._timer.addListener(TimerType.ENTERFRAME, this.onEverySecondUpdateForce);
            }
            if (!this._timer.running)
            {
                this._timer.start();
            }
            return;
        }// end function

        private function onEverySecondUpdateForce(param1 = null) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this._leftTime - 1;
            _loc_2._leftTime = _loc_3;
            if (this._leftTime <= 0)
            {
                this.flyBootHandler();
                return;
            }
            this._btn.label = Language.getStringByParam(21028, this._leftTime);
            return;
        }// end function

        public function updateDatas(param1:TaskInfo) : void
        {
            this._info = param1;
            this._txt.htmlText = Language.getStringByParam(21029, TaskUtil.getLinkTargetName(param1));
            this._leftTime = 6;
            this.startTimer();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._txt = UIFactory.gTextField("", 50, 60, 300, 20, this);
            this._btn = UIFactory.gButton(Language.getString(21030), 104, 124, 88, 22, this);
            this._btn.configEventListener(MouseEvent.CLICK, this.flyBootHandler);
            return;
        }// end function

        private function flyBootHandler(param1 = null) : void
        {
            this.hide();
            if (this._info == null)
            {
                return;
            }
            var _loc_2:* = this._info.getCurLinkData();
            if (_loc_2 == null)
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.FlyBoot_GLinkText, _loc_2));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._info = null;
            this._txt.dispose(param1);
            this._txt = null;
            this._btn.dispose(param1);
            this._btn = null;
            if (this._timer != null)
            {
                this._timer.stop();
                this._timer.dispose(true);
                this._timer = null;
            }
            return;
        }// end function

        public static function get instance() : GuideTaskFlyWin
        {
            if (_instance == null)
            {
                _instance = new GuideTaskFlyWin;
            }
            return _instance;
        }// end function

    }
}
